from flask_sqlalchemy import SQLAlchemy
import datetime

db = SQLAlchemy()

class User(db.Model):
    id = db.Column(db.Integer,primary_key = True,autoincrement = True)
    username = db.Column(db.String(20),unique = True,nullable = False)
    password = db.Column(db.String(120),nullable = False)
    phone = db.Column(db.String(11),nullable =False )
    photo = db.Column(db.String(200))
    isanmin = db.Column(db.Boolean,default = False)

class Cate(db.Model):
    id = db.Column(db.Integer,primary_key = True,autoincrement = True)
    name = db.Column(db.String(120),unique = True,nullable = False)

    news = db.relationship("News", backref="cate")

class News(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(20), unique=True)
    content = db.Column(db.Text)
    count = db.Column(db.Integer, default=0)
    created = db.Column(db.DateTime, default=datetime.datetime.now)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    cate_id = db.Column(db.Integer, db.ForeignKey("cate.id"))
    pic = db.Column(db.String(50))
    status = db.Column(db.Integer, default=0)  # 0未审核， 1 审核中 2审核通过 3审核失败
    reason = db.Column(db.String(200))  # 审核不通过的原因